<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/WEB-INF/jsp/taglibs-struts2.jsp" %>

<script type="text/javascript" src="<c:url value="/script/prototype.js"/>"></script>
<script type="text/javascript" src="<c:url value="/script/stringfunc.js"/>"></script>

<div class="right">
<div class="right600"><img src="<c:url value="/images/a01.jpg"/>" /></div>
<s:form namespace="/flight" action="flightQueryAction!query" method="post" name="queryform">
<div class="right600b"><h2><img src="<c:url value="/images/r101.jpg"/>" /></h2><h2 class="r101"></h2><h2><img src="<c:url value="/images/r103.jpg"/>" /></h2></div>
<div class="rightk">
  <h3><font color="#CC0000">*</font>出发地：</h3>
  <h2><select id="depart_continent" name="departContinentSel" size="1" onchange="changeContinent('depart')"></select></h2>
  <h2>
    <select id="depart_country" name="departCountrySel" size="1" onchange="changeCountry('depart')"></select>
  </h2>
  <h2><select id="depart_airport" name="departure" ></select></h2>
</div>

<div class="rightk">
  <h3><font color="#CC0000">*</font>目的地：</h3>
  <h2><select id="dest_continent" name="destContinentSel" size="1" onchange="changeContinent('dest')"></select></h2>
  <h2>
    <select id="dest_country" name="destCountrySel" size="1" onchange="changeCountry('dest')"></select>
  </h2>
  <h2><select id="dest_airport" name="destination"></select></h2>
</div>

<div class="rightk">
  <h3>&nbsp;</h3>
  <h3><input type="checkbox" name="queryCityAirport" value="1" id="queryCityAirportId"/><label id="queryCityAirportId">查询同城市其他机场航班</label></h3>
</div>

<div class="rightk"><h3>类型：</h3><h2><select name="itineryType" onchange="changeItinery(this)">
  <option value="1">往返</option>
  <option value="0">单程</option>
</select>
</h2></div>

<div class="rightk"><h3><font color="#CC0000">*</font>
  出发日期：</h3><h2><s:textfield name="toDate" cssStyle="width:70px"/></h2>
  <h2 id="backDateTitle" style="display: block;">回程日期：</h2><h2 id="backDateInput" style="display: block;"><s:textfield name="backDate" cssStyle="width:70px"/></h2>
</div>

<div class="rightk"><h3>舱位等级：</h3><h2>
  <s:select name="bunk" list="#{'Y':'经济舱', 'F':'头等舱', 'C':'公务舱'}"/>
</h2></div>
<div class="rightk"><h3>旅客类型：</h3><h2><select name="select">
  <option>成人</option>
  <option>学生</option>
</select>
</h2></div>
<div class="rightk"><h3>人数目：</h3><h2><select name="passengersNum">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
</select>
</h2></div>
<div class="rightk"><h3>航空公司：</h3><h2>
  <select id="carrierId" name="carrier" size="1" onchange="changeAirCompany(this)">
    <c:forEach var="com" items="${twoCodeList}">
      <option value="<c:out value="${com.twocode}"/>"><c:out value="${com.twocode}"/> - <c:out value="${com.comChineseName}"/></option>
    </c:forEach>
  </select>
</h2></div>
<div class="rightk"><h3>转机地：</h3><h2><select id="turncityId" name="turncity" onchange="changeTransferCity(this)">
  <option value="00">(无)</option>
  <c:forEach var="tc" items="${turncityList}">
  <option value="<c:out value="${tc.airportThreeCode}"/>"><c:out value="${tc.airportThreeCode} - ${tc.airportChineseName}"/></option>
  </c:forEach>
</select>
</h2></div>

<div class="rightk2"><h3></h3>
  <h2><img src="<c:url value="/images/t01.jpg"/>" onclick="submitQuery()"/></h2>
  <h2><img src="<c:url value="/images/t02.jpg"/>" /></h2>
</div>
</s:form>
</div>

<%@include file="dynamicCC.jsp" %>

<script type="text/javascript">
displayContinent("depart");
displayContinent("dest");
function submitQuery() {
  window.document.queryform.submit();
}
function changeItinery(selCtl) {
  var backDateTitle = document.getElementById("backDateTitle");
  var backDateInput = document.getElementById("backDateInput");
  var val = selCtl.value;
  if(val == '0') {
    backDateTitle.style.display = 'none';
    backDateInput.style.display = 'none';
  } else {
    backDateTitle.style.display = 'block';
    backDateInput.style.display = 'block';
  }
}

var turncityId = $("turncityId");
var carrierId = $("carrierId");

function changeAirCompany(selCtl) {
var val = selCtl.options[selCtl.selectedIndex].value;
var url = "<%=basePath%>flight/flightQueryAction!getTransAirport.action?company=" + val + "&r=" + getRandomString();
//alert("url is:" + url);
new Ajax.Request(url, {
  method: "get",
  onComplete: function(transport) {
    var ret = transport.responseText.trim();
    var currTC = turncityId.options[turncityId.selectedIndex].value;
    if(currTC != '00' && currTC != ret) {
      selectOption(turncityId, ret);
    }
  }
});
}

function changeTransferCity(selCtl) {
var val = selCtl.options[selCtl.selectedIndex].value;
var url = "<%=basePath%>flight/flightQueryAction!getTransCompany.action?airport=" + val + "&r=" + getRandomString();
//alert("url is:" + url);
new Ajax.Request(url, {
  method: "get",
  onComplete: function(transport) {
    var ret = transport.responseText.trim();
    var currTC = carrierId.options[carrierId.selectedIndex].value;
    
    if(currTC != '00' && currTC != ret) {
      selectOption(carrierId, ret);
    }
  }
});
}

function selectOption(selCtl, value) {
var options = selCtl.options;
var selIndex = -1;
for(var i = 0; i < options.length; i ++) {
  if(options[i].value == value) {
    selIndex = i;
  }
}
if(selIndex != -1) {
  selCtl.selectedIndex = selIndex;
}
}
</script>